package com.example.processor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class CustomBeanPostProcessor implements BeanPostProcessor {

    private static final Logger logger = LoggerFactory.getLogger(CustomBeanPostProcessor.class);

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (beanName.equals("myBean")) { // 只处理名为 "myBean" 的 bean
            logger.info("Before Initialization: {}", beanName);
            // 在这里添加指定的处理逻辑
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (beanName.equals("myBean")) { // 只处理名为 "myBean" 的 bean
            logger.info("After Initialization: {}", beanName);
            // 在这里添加指定的处理逻辑
        }
        return bean;
    }
}
